
var url='https://www.cailianxinwen.com'
var flag=true
$('#login').click(function(){

    var tel=$('.input_txt').val()
    var code=$('#code').val()
    console.log(tel)
    console.log(code)
    if(tel=='')
    {
        alert('请填写手机号');
        return;
    }
    if(code=='')
    {
        alert('请填写验证码')
        return;
    }

    $.ajax({
        type: "post",
        url: url+'/app/blog/htmlRegister?account='+tel+'&checkcode='+code,
         dataType: "json",
         //jsonp: "jsoncallback",
         success: function (json) {
            console.log(json)//

//判断登录
            if(json.code==1104)
            {
                window.location.href='sm.html'
       
                tm='{"tel":"'+tel+'","state":1104,"userid":"'+json.userid+'"}'
            }
            else if(json.code==1105)
            {
                window.location.href='message.html'
     
                tm='{"tel":"'+tel+'","state":1105,"userid":"'+json.userid+'"}'
            }
            else{
                tm='{"tel":"'+tel+'","state":0,"userid":"0"}'
            }
            sessionStorage.setItem('clbnb',tm)
         },
         error: function (err) {
             console.log(err)
         }
     });
})
$('#aa').click(function(){
 if(flag)
 {
    console.log('a')
    sendcode()
 }
   
})

var token=''
function gettoken(t){
    console.log(t)
    $.ajax({
        type: "post",
        url: url+'/app/blog/getT?mobile='+t,
         dataType: "text",
         //jsonp: "jsoncallback",
         success: function (json) {
            console.log(json)//获取token
            token=json
            checkcode(t,json) //验证短信
        },
         error: function (err) {
             console.log(err)
         }
     });
}
function checkcode(t,c)
{
    $.ajax({
        type: "post",
        url: url+'/app/blog/getCheckCode?mobile='+t+'&token='+c,
         dataType: "json",
         //jsonp: "jsoncallback",
         success: function (json) {
            console.log(json)
         
        },
         error: function (err) {
             console.log(err)
         }
     });
}

function sendcode(){
    var tel=$('.input_txt').val()
    gettoken(tel) //发送验证码
        flag=false
        var time = 60;
     var intervalID=   setInterval(function(){
        time--;
        $(".input_txt3").text(time+'s');
        if(time==0)
        {
            $(".input_txt3").text('重新发送');
            flag=true
            clearInterval(intervalID);
        }
        }, 1000);
       
}

var typelist=['','求助','咨询','建言','投诉','感谢']
var userid=''



function getlist(pagenumber,userids){
    var _html=''
    $.ajax({
        type: "post",
        url: url+'/app/blog/getBlogDetailList?pagenow='+pagenumber+'&userid='+userids,
         dataType: "json",
         //jsonp: "jsoncallback",
         success: function (json) {
             console.log(json)
             if(pagenumber==1)
             {       
                $.each(json.list, function(index, value) {
                    _html+='<a href="listshow2.html?id='+value.id+'"><li>'
                    _html+='<div class="float_left num">'+(index+1)+'</div>'
                    _html+='<div class="float_left con">'
                    _html+='<h3><span class="hot">'+typelist[value.type]+'</span>&nbsp;|&nbsp;'+value.content+'</h3>'
                    _html+='<h5>'+value.posttime+'</h5>'
                    _html+='</div><div class="clear"></div>'
                    _html+='</li></a>'
            
                        
                  });
                  $('.listbox').html(_html)
                  $('.num').first().removeClass('num').addClass('num01')
                  $('.num').first().removeClass('num').addClass('num02')
                  $('.num').first().removeClass('num').addClass('num03')
             }
             else{
                $.each(json.list, function(index, value) {
                    _html+='<a href="listshow2.html?id='+value.id+'"><li>'
                    _html+='<div class="float_left num">'+(8*(pagenumber-1)+index+1)+'</div>'
                    _html+='<div class="float_left con">'
                    _html+='<h3><span class="hot">'+typelist[value.type]+'</span>&nbsp;|&nbsp;'+value.content+'</h3>'
                    _html+='<h5>'+value.posttime+'</h5>'
                    _html+='</div><div class="clear"></div>'
                    _html+='</li></a>'
                        
                  });
                  $('.listbox').append(_html)
             }
           
         },
         error: function (err) {
             console.log(err)
         }
     });
}


